<template>
  <CustomDialog :drag-dialog="dialogInfo" style="z-index:1201;">
    <el-form ref="form" :model="form" :disabled="true" size="mini" label-width="160px">
      <el-row :gutter="2">
        <el-col :span="12">
          <el-form-item label="请求用户" prop="busMainData.createBy">
            <el-input v-model="form.busMainData.createBy" />
          </el-form-item>
          <el-form-item label="日志信息描述" prop="busMainData.logInfo">
            <el-input v-model="form.busMainData.logInfo" />
          </el-form-item>
          <el-form-item label="请求IP" prop="busMainData.requestIp">
            <el-input v-model="form.busMainData.requestIp" />
          </el-form-item>
          <el-form-item label="花费时间" prop="busMainData.costTime">
            <el-input v-model="form.busMainData.costTime" />
          </el-form-item>
          <el-form-item label="类名" prop="busMainData.className">
            <el-input v-model="form.busMainData.className" />
          </el-form-item>
          <el-form-item label="方法名" prop="busMainData.methodName">
            <el-input v-model="form.busMainData.methodName" />
          </el-form-item>
          <el-form-item label="请求参数" prop="busMainData.requestParam">
            <el-input v-model="form.busMainData.requestParam" rows="4" type="textarea"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="时间" prop="busMainData.lastUpdateDate">
            <el-date-picker
              v-model="form.busMainData.lastUpdateDate"
              placeholder="时间"
              type="datetime"
              size="mini"
              clearable
              style="width: 200px"
              class="filter-item" />
          </el-form-item>
          <el-form-item label="对象ID" prop="busMainData.objectId">
            <el-input v-model="form.busMainData.objectId" />
          </el-form-item>
          <el-form-item label="对象编号" prop="busMainData.objectCode">
            <el-input v-model="form.busMainData.objectCode" />
          </el-form-item>
          <el-form-item label="业务模块" prop="busMainData.busModule">
            <el-input v-model="form.busMainData.busModule" />
          </el-form-item>
          <el-form-item label="日志级别" prop="busMainData.logLevel">
            <el-input v-model="form.busMainData.logLevel" />
          </el-form-item>
          <el-form-item label="日志类别" prop="busMainData.logType">
            <el-input v-model="form.busMainData.logType" />
          </el-form-item>
          <el-form-item label="响应参数" prop="busMainData.responseResult">
            <el-input v-model="form.busMainData.responseResult" rows="4" type="textarea"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </CustomDialog>
</template>

<script>
import baseOperateLog from '@/api/base/BaseOperateLog'

export default {
  components: { },
  props: {
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      isAdd: false,
      loading: false,
      style: 'width: 184px',
      dialogInfo: {
        name: 'baseOperateLogMngFormDialog',
        title: '系统日志管理',
        fullScreen: false,
        width: 800,
        height: 80
      },
      form: {
        busMainData: {
          id: '',
          enableFlag: 'Y'
        },
        busPageInfo: {
          editable: false
        }
      },
      rules: {
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    initDataOfBefore() {
    },
    displayDialog() {
      const { name } = this.dialogInfo
      this.$nextTick(() => {
        this.$modal.show(name)
      })
    },
    hiddenDialog() {
      const { name } = this.dialogInfo
      this.$nextTick(() => {
        this.$modal.hide(name)
      })
    },
    addData() {
      this.isAdd = true
      const data = { paramBean: {}}
      baseOperateLog.toAdd(data).then(res => {
        this.displayDialog()
        this.form = res.data
      }).catch(err => {
        console.log(err)
      })
    },
    copyData(mainId) {
      this.isAdd = true
      const data = { paramBean: { id: mainId }}
      baseOperateLog.toCopy(data).then(res => {
        this.displayDialog()
        this.form = res.data
      }).catch(err => {
        console.log(err)
      })
    },
    viewMainData(id) {
      this.isAdd = false
      const data = { paramBean: { id: id }}
      baseOperateLog.viewMainData(data).then(res => {
        this.displayDialog()
        this.form = res.data
      })
    },
    doSubmit() {
      this.doSingleSave(true)
    },
    doSave() {
      this.doSingleSave(false)
    },
    doSingleSave(isSubmit) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.form.formSubmit = isSubmit
          this.loading = true
          if (this.isAdd) {
            this.doAdd()
          } else {
            this.doEdit()
          }
        }
      })
    },
    doAdd() {
      baseOperateLog.addOrEdit(this.form).then(res => {
        this.resetForm()
        this.loading = false
        this.sup_this.init()
      }).catch(err => {
        this.loading = false
        console.log(err)
      })
    },
    doEdit() {
      baseOperateLog.addOrEdit(this.form).then(res => {
        this.resetForm()
        this.loading = false
        this.sup_this.init()
      }).catch(err => {
        this.loading = false
        console.log(err)
      })
    },
    resetForm() {
      this.hiddenDialog()
      this.$refs['form'].resetFields()
    },
    changeData(busId) {
      const data = { paramBean: { id: busId }}
      baseOperateLog.toChange(data).then(res => {
        this.displayDialog()
        this.form = res.data
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>
